class Solution {
    bool vis[16];
    int ret;
 
public:
    int countArrangement(int n) {
        dfs(1, n);
        return ret;
    }
 
    void dfs(int pos, int n)
    {
        if(pos == n + 1) // 下标从1到n
        {
            ++ret;
            return;
        }
        
        for(int i = 1; i <= n; ++i)
        {
            if(!vis[i] && (pos % i == 0 || i % pos == 0))
            {
                vis[i] = true;
                dfs(pos + 1, n);
                vis[i] = false;
            }
        }
    }
};